#!/usr/bin/env python
#encoding=utf8

#迭代器
def my_range(n):
    i = 0
    while i < n:
        yield i
        i += 1


for i in my_range(10):
    print i

#协程

def coroutine(func):
    def start(*args, **kwargs):
        g = func(*args, **kwargs)
        g.next()
        return g
    return start

@coroutine
def receiver():
    print "ready to receive"
    while 1:
        n = (yield)
        print("Got %s", n)

r = receiver()
r.send(1)
r.send(2)
r.send("hello world")
r.close()

